package com.jaws.core.common.shard.algorithm;

import org.springframework.stereotype.Component;

/**
 * 分表算法基类
 *
 * @author liangqm
 * @date 2018-05-04 19:45:18
 * @since v1.0.2
 */
public class BaseShardAlgorithm {

	/**
	 * 返回表的segment
	 *
	 * @param table     TableNameEnum
	 * @param balanceId table id
	 * @return table segment
	 * @author maojian
	 * @date 2017-09-02 14:16:47
	 * @since v1.0.0
	 */
	public String getTableSegment(String table, String balanceId) {
		String hashCode = String.valueOf(balanceId.hashCode());
		long segment = Math.abs(Long.parseLong(hashCode)) % 8;
		return table + segment;
	}

}
